package com.youlv.yl.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.web.bind.annotation.CrossOrigin;

import static jdk.nashorn.internal.objects.Global.undefined;

/**
 * @author fenghe
 * @date 2022/1/15 16:35
 */
@Configuration
@EnableWebSecurity
@CrossOrigin

public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable()
                .authorizeRequests()
                .antMatchers("/user/**").access("hasRole('ADMIN') or hasRole('USER')")
                .and().formLogin().permitAll();
        //以下这句就可以控制单个用户只能创建一个session，也就只能在服务器登录一次
        http.sessionManagement().maximumSessions(1).expiredUrl("/");

    }
}
